package com.hzy.quetosys.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hzy.quetosys.dao.IncomeMapper;
import com.hzy.quetosys.entity.Income;
import com.hzy.quetosys.entity.Product;
import com.hzy.quetosys.service.IncomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class IncomeServiceImpl implements IncomeService {
    @Autowired
    private IncomeMapper incomeMapper;
    @Override
    public PageInfo<Income> findAll(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        final List<Income> incomes = incomeMapper.selectAll();
        PageInfo<Income> pageInfo=new PageInfo<>(incomes);
        return pageInfo;
    }

    @Override
    public PageInfo<Income> findByKeyword(int pageNum, int pageSize, String keyword) {
        PageHelper.startPage(pageNum,pageSize);
        List<Income> incomes=incomeMapper.selectByKeyword(keyword);
        PageInfo<Income> pageInfo=new PageInfo<>(incomes);
        return pageInfo;
    }

    @Override
    public boolean append(Income income) {
        return incomeMapper.insert(income) > 0;
    }

    @Override
    public Income findById(int id) {
        return incomeMapper.selectById(id);
    }

    @Override
    public boolean modify(Income income) {
        return incomeMapper.updateById(income)>0;
    }

    @Override
    public boolean remove(int id) {
        return incomeMapper.deleteById(id) > 0;
    }
}
